<?php
	class Templater extends Zend_View_Abstract{
		protected $_path;
		protected $_engine;

		public function __construct($theme = 'default'){
			require_once(ROOT_PATH.'/system/Smarty/Smarty.class.php');
			$this->_engine = new Smarty();
			$this->_engine->caching = FALSE;
			$this->_engine->cache_lifetime = 100;
			$this->_engine->template_dir = ROOT_PATH . '/app/templates/' . $theme;
			$this->_engine->cache_dir = sprintf ( '%s/tmp/smarty_cache/' . $theme, ROOT_PATH . '/data' );
			$this->_engine->compile_dir = sprintf ( '%s/tmp/templates_c/' . $theme, ROOT_PATH . '/data' );
			$this->_engine->plugins_dir = array(ROOT_PATH.'/include/plugins', ROOT_PATH.'/system/Smarty/plugins');
		}

		public function getEngine(){
			return $this->_engine;
		}

		public function __set($key, $val) {
			$this->_engine->assign ( $key, $val );
		}

		public function __get($key) {
			$this->_engine->getTemplateVars ( $key );
		}

		public function __isset($key) {
			return $this->_engine->getTemplateVars ( $key ) !== null;
		}

		public function __unset($key) {
			$this->_engine->clearAssign ( $key );
		}

		public function assign($spec, $value = null) {
			if (is_array ( $spec )) {
				$this->_engine->assign ( $spec );
				return;
			}

			$this->_engine->assign ( $spec, $value );
		}

		public function clearVars() {
			$this->_engine->clearAllAssign ();
		}

		public function render($name) {
			return $this->_engine->fetch ( strtolower ( $name ) );
		}

		public function _run() {
		}

		public function isCached($template, $cache_id = null) {
			return $this->_engine->isCached ( $template, $cache_id );
		}
	}
?>